package com.zenika.zenbinding.client.handler;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Widget;
import com.zenika.zenbinding.client.widget.RadioGroup;

public class RadioListHandler extends ListBindingHandler implements ChangeListener {

	private RadioGroup radioList;

	public RadioListHandler(RadioGroup radioList, List valueList) {
		super();
		radioList.addChangeListener(this);
		this.radioList = radioList;
		// FIXME this.model.setHandler(this);
		this.setChoices(valueList);
	}

	public void setErrorStyle() {
		// TODO
	}

	public void setRegularStyle() {
		// TODO
	}

	public void onChange(Widget sender) {
		String item = this.radioList.getSelectedItem();
		List result = new ArrayList();
		result.add(this.getObject(item));
		this.fireChange(result);
	}

	public void addItem(String item) {
		this.radioList.addItem(item);
	}

	public void setItemSelected(String item, boolean selected) {
		if (selected) {
			this.radioList.setItemSelected(item);
		}
	}

	public Widget getWidget() {
		return this.radioList;
	}

	public Object getValue() {
		// FIXME check implementation
		return this.radioList.getSelectedItem();
	}

}
